Skip to content

Conversation

@antonwolfy
Copy link
Contributor

@antonwolfy antonwolfy commented Jan 27, 2026

The PR changes implementation of strides property in dpnp.ndarray to align with NumPy and CuPy and to return bytes displacement in memory (previously and in dpctl it returns elements displacement).

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.20.0 release milestone Jan 27, 2026
@antonwolfy antonwolfy self-assigned this Jan 27, 2026
@github-actions
Copy link
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2747/index.html

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

Array API standard conformance tests for dpnp=0.20.0dev2=py313h509198e_28 ran successfully.
Passed: 1353
Failed: 2
Skipped: 9

@coveralls
Copy link
Collaborator

coveralls commented Jan 27, 2026

Coverage Status

coverage: 81.105% (+0.002%) from 81.103%
when pulling a759850 on align-strides-with-numpy
into 1f7f4d9 on master.

@antonwolfy antonwolfy force-pushed the align-strides-with-numpy branch from 3b983e6 to 53bebfd Compare January 28, 2026 11:02
@antonwolfy antonwolfy force-pushed the align-strides-with-numpy branch from 53bebfd to d6ead2f Compare January 28, 2026 12:05
@antonwolfy antonwolfy marked this pull request as ready for review January 28, 2026 12:08
@antonwolfy antonwolfy linked an issue Jan 28, 2026 that may be closed by this pull request
out_offset = st_m // a.itemsize * offset
else:
out_shape = a_shape[:-2] + (0,)
out_strides = a_straides[:-2] + (1,)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic here also needs to be updated because currently dpnp returns incorrect strides compared to NumPy. Could you also add a test to cover this case?

a = dpnp.arange(10).reshape(2,5)
a_np = numpy.arange(10).reshape(2,5)

dpnp.diagonal(a, offset=5).strides
# (0. )

numpy.diagonal(a_np, offset=5).strides
# (48, )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that wasn't aligned on the master as well:

a = np.arange(10).reshape(2,5)
np.diagonal(a, offset=5).strides
# Out: (1,)

Btw I will update the code to keep the same behavior as was on the master. But I wonder if there is a strict requirement on strides equality with NumPy for a 0-size array. In any case it'd be better to handle that (if needed) in the seprarte PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonwolfy Thanks for bringing this distinction. Just curious to know if dpnp/dpctl recommends any particular numpy version dependency for testing. The app I was working with failed too with the diagonal method in stacktrace.

Would the below legacy behavior be restored, only when the offsets is outside the bounds and rest of the functionality to changed to number of bytes from number of items ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious to know if dpnp/dpctl recommends any particular numpy version dependency for testing.

We are targeting to align with the latest published numpy version.

The app I was working with failed too with the diagonal method in stacktrace.

Could you please share an example of the code with failure? It might be some other issue we have to resolve.

Would the below legacy behavior be restored, only when the offsets is outside the bounds and rest of the functionality to changed to number of bytes from number of items ?

Everywhere it will be to return the number of bytes.
In case when the offsets is outside the bounds, previously dpnp returns strides end with ...,1), and now it will end with ..., 1 * a.itemsize).
The "legacy" in that use case means "different from the numpy" for returned 0-sized array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DPNP vs Numpy strides mismatch

4 participants